package com.sunshine.student_register.ui.activity.manager;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import com.sunshine.student_register.database.StudentRegisterRepository;
import com.sunshine.student_register.database.register.RegisterEntity;
import com.sunshine.student_register.database.student.StudentEntity;

import java.util.List;

/**
 * @author sunshine
 * @date 2020/5/30
 */
public class ManagerViewModel extends AndroidViewModel {

    private StudentRegisterRepository repository;
    private MutableLiveData<List<StudentEntity>> studentLiveData;
    private MutableLiveData<List<RegisterEntity>> registerLiveData;

    public ManagerViewModel(@NonNull Application application) {
        super(application);
        repository = new StudentRegisterRepository(getApplication());
        studentLiveData = new MutableLiveData<>();
        registerLiveData = new MutableLiveData<>();
        studentLiveData.setValue(null);
        registerLiveData.setValue(null);
    }

    MutableLiveData getStudentLiveData(){
        studentLiveData.setValue(repository.getAllStudent());
        return studentLiveData;
    }

    MutableLiveData getRegisterLiveData(){
        registerLiveData.setValue(repository.getAllRegister());
        return registerLiveData;
    }

    void updateStudent(StudentEntity studentEntity){
        repository.updateStudent(studentEntity);
    }

    void deleteStudent(StudentEntity studentEntity){
        repository.deleteStudent(studentEntity);
    }

    void deleteAllStudent(){
        repository.deleteAllStudent();
    }

    void deleteAllRegister(){
        repository.deleteAllRegister();
    }
}
